package com.stqf.scala.grammar.collection

/**
  * Created by ASUS on 2018-02-01.
  */
object ListLearn {
  def main(args: Array[String]): Unit = {
    var search: List[String] = List("baidu", "google", "sohu")
    println("List创建:" + search)
    search = search.updated(2, "Tencent")
    println("List修改:" + search)
    search = search.drop(1)
    println("List删除:" + search)
    val index = search.indexOf("google")
    println("List根据元素查找索引:" + index)
    search = "360" +: search
    println("List头部添加单个元素:" + search)
    search = search :+ "firefox"
    println("List尾部添加单个元素:" + search)
    search = search ::: List("ie", "QQBrowsere")
    println("List拼接:" + search)
    println("browsers的第一个元素:" + search.head)
    println("browsers(除第一个元素)剩余元素:" + search.tail)
    println("browsers是否为空:" + search.isEmpty)
    val temp = List(
      Tuple2("sohu", "www.sohu.com"),
      "baidu" -> "www.baidu.com",
      "google" -> "www.google.com"
    )
    val maps = temp.toMap[String, String]
    maps.keys.foreach(key => println(key + "\t" + maps(key)))
    //Scala 类型约束:https://segmentfault.com/a/1190000004854644

  }
}
